package com.quasar.hpatient.module.discover_recommend;

import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.bean.discover.DiscoverRecommendBean;

import java.util.ArrayList;

import lib.quasar.base.frame.BasePresenter;
import lib.quasar.context.BaseApp;
import lib.quasar.recycler.BaseCommonAdapter;
import lib.quasar.recycler.holder.RecyclerHolder;
import lib.quasar.recycler.manager.CrashLinearLayoutManager;

/**
 * description: 发现 ==> 推荐资讯
 * created by kalu on 2018/3/19 16:14
 */
public class DiscoverRecommendPresenter implements BasePresenter {

    private final ArrayList<DiscoverRecommendBean> mData = new ArrayList<>();

    {
        mData.add(new DiscoverRecommendBean());
        mData.add(new DiscoverRecommendBean());
        mData.add(new DiscoverRecommendBean());
        mData.add(new DiscoverRecommendBean());
        mData.add(new DiscoverRecommendBean());
        mData.add(new DiscoverRecommendBean());
        mData.add(new DiscoverRecommendBean());
    }

    void initList(DiscoverRecommendView view, RecyclerView recycler) {

        if (null == view || null == recycler) return;

        final BaseCommonAdapter<DiscoverRecommendBean> adapter = new BaseCommonAdapter<DiscoverRecommendBean>(mData, R.layout.fragment_discover_recommend_chind) {

            @Override
            protected void onNext(RecyclerHolder holder, final DiscoverRecommendBean model, final int position) {
                // 图片
                ImageView image = holder.getView(R.id.fragment_discover_recommend_chind_image);
                view.setImage(image, model.getUrl());
                // 标题信息
                view.setText(holder, R.id.fragment_discover_recommend_chind_title, model.getTitle());
                // 文字信息
                view.setText(holder, R.id.fragment_discover_recommend_chind_info, model.getInfo());
                // 点击监听
                holder.itemView.setOnClickListener(v -> view.goWeb(model.getUrl()));
            }
        };

        adapter.setNullView(BaseApp.getContext(), R.layout.layout_recycler_loading);
        final CrashLinearLayoutManager manager = new CrashLinearLayoutManager(BaseApp.getContext());
        view.setRecycler(recycler, adapter, manager);
    }

    @Override
    public void recycler() {
        mData.clear();
    }
}